File System Creation and Mounting Lab

1. Add Partitions, File Systems, and Persistent Mounts

In this lab, you create an MBR partition on a newly allocated disk, format the partition with an ext4 file system, and configure the file system for persistent mounting.

You have been asked to archive data to a new directory, /archive, on server1.example.com. You have been allocated a second disk for this purpose. The /archive directory requires 1 GiB of space. To make sure that the /archive directory is always available for use, you need to configure the newly created file system to be persistently mounted at /archive even after a server reboot.

Once you have completed your work, reboot your server1.example.com machine and verify that the newly created file system is persistently mounted at /archive after the reboot.

  1. Log in to server1.example.com.

  2. Switch to root using sudo -i.

  3. Create a 1 GiB MBR partition on /dev/vdb of type Linux.

    1. Use fdisk to modify the second disk.

      [root@server1 ~]# fdisk /dev/vdb
    2. Display the original partition table, then add a new partition that is 1 GiB in size.

      Command (m for help):p
      
      Disk /dev/vdb:10.7 GB, 10737418240 bytes, 20971520 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical):512 bytes / 512 bytes
      I/O size (minimum/optimal):512 bytes / 512 bytes
      Disk label type:dos
      Disk identifier:0xfd41a9d3
      
      Device Boot    Start      End   Blocks  Id  System
      
      Command (m for help):n
      Partition type:
         p   primary (0 primary, 0 extended, 4 free)
         e   extended
      Select (default p):p
      Partition number (1-4, default 1):1
      First sector (2048-20971519, default 2048):Enter
      Using default value 2048
      Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G
      Partition 1 of type Linux and of size 1 GiB is set
    3. Save the partition table changes.

      Command (m for help):w
      The partition table has been altered!
      
      Calling ioctl() to re-read partition table.
      Syncing disks.
    4. If fdisk issues a warning, then run the partprobe command to make the kernel aware of the partition table change. This will not be necessary if the disk device is currently unused.

      [root@server1 ~]# partprobe
  4. Format the newly created partition with the ext4 file system.

    [root@server1 ~]# mkfs -t ext4 /dev/vdb1
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type:Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    65536 inodes, 262144 blocks
    13107 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=268435456
    8 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376
    
    Allocating group tables:done
    Writing inode tables:done
    Creating journal (8192 blocks):done
    Writing superblocks and filesystem accounting information:done
  5. Configure the newly created file system to persistently mount at /archive.

    1. Create the /archive directory mount point.

      [root@server1 ~]# mkdir /archive
    2. Determine the UUID of the new partition on the second disk.

      [root@server1 ~]# blkid /dev/vdb1
      /dev/vdb1:UUID="5fcb234a-cf18-4d0d-96ab-66a4d1ad08f5" TYPE="ext4"
    3. Add an entry to /etc/fstab. Replace the UUID value with the UUID from the previous command.

      UUID=[UUID FROM PREVIOUS COMMAND] /archive ext4 defaults 0 2
  6. Test mounting the newly created file system.

    1. Execute the mount command to mount the new file system using the new entry added to /etc/fstab.

      [root@server1 ~]# mount -a
    2. Verify that the new file system is mounted at /archive.

      [root@server1 ~]# mount | grep -w /archive
      /dev/vdb1 on /archive type ext4 (rw,relatime,seclabel,data=ordered)
  7. Reboot server1.example.com. After the server has rebooted, log in and verify that /dev/vdb1 is mounted at /archive.

    [root@server1 ~]# mount | grep -w /archive
    /dev/vdb1 on /archive type ext4 (rw,relatime,seclabel,data=ordered)

You now have a 1 GiB ext4 file system on second disk that is persistently mounted at /archive.

2. Add and Enable Swap Space

In this lab, you create a swap partition and enable it for use.

No swap partition was created during the installation of server1.example.com. During peak usage, the server has been running out of physical memory. You have ordered additional RAM and are anxiously waiting for its arrival. In the meantime, you decide to alleviate the problem by enabling swap space on the second disk. To make sure that the newly added swap space is always available for use, you also need to configure it to be enabled upon boot.

Once you have completed your work, reboot your server1.example.com machine and verify that the swap space is available after the reboot.

  1. Log in to server1.example.com.

  2. Switch to root using sudo -i.

  3. Create a 500 MiB partition on /dev/vdb of type Linux swap.

    1. Use fdisk to modify the second disk.

      [root@server1 ~]# fdisk /dev/vdb
    2. Print the original partition table, then create a new partition that is 500 MiB in size.

      Command (m for help):p
      
      Disk /dev/vdb:10.7 GB, 10737418240 bytes, 20971520 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical):512 bytes / 512 bytes
      I/O size (minimum/optimal):512 bytes / 512 bytes
      Disk label type:dos
      Disk identifier:0xfd41a9d3
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/vdb1            2048     2099199     1048576   83  Linux
      
      Command (m for help):n
      Partition type:
         p   primary (1 primary, 0 extended, 3 free)
         e   extended
      Select (default p):p
      Partition number (2-4, default 2) 2
      First sector (2099200-20971519, default 2099200):Enter
      Using default value 2099200
      Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519):+500M
      Partition 2 of type Linux and of size 500 MiB is set
      
      Command (m for help):p
      
      Disk /dev/vdb:10.7 GB, 10737418240 bytes, 20971520 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical):512 bytes / 512 bytes
      I/O size (minimum/optimal):512 bytes / 512 bytes
      Disk label type:dos
      Disk identifier:0xfd41a9d3
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/vdb1            2048     2099199     1048576   83  Linux
      /dev/vdb2         2099200     3123199      512000   83  Linux
      
    3. Set the newly created partition to type Linux swap.

      Command (m for help):t
      Partition number (1,2, default 2):2
      Hex code (type L to list all codes):L
      
      ...
       1 FAT12  27 Hidden NTFS Win  82 Linux swap / So c1  DRDOS/sec (FAT-
      ...
      Hex code (type L to list all codes):82
      Changed type of partition Linux to Linux swap / Solaris
      
      Command (m for help):p
      
      Disk /dev/vdb:10.7 GB, 10737418240 bytes, 20971520 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical):512 bytes / 512 bytes
      I/O size (minimum/optimal):512 bytes / 512 bytes
      Disk label type:dos
      Disk identifier:0xfd41a9d3
      
      Device Boot    Start      End   Blocks  Id  System
      /dev/vdb1       2048  2099199  1048576  83  Linux
      /dev/vdb2    2099200  3123199   512000  82  Linux swap / Solaris
    4. Save the partition table changes.

      Command (m for help):w
      The partition table has been altered!
      
      Calling ioctl() to re-read partition table.
      
      WARNING:Re-reading the partition table failed with error 16: Device or resource busy.
      The kernel still uses the old table. The new table will be used at
      the next reboot or after you run partprobe(8) or kpartx(8)
      Syncing disks.
    5. Run partprobe to make the kernel aware of the partition table change.

      [root@server1 ~]# partprobe
  4. Initialize the newly created partition as swap space.

    [root@server1 ~]# mkswap /dev/vdb2
    Setting up swapspace version 1, size = 511996 KiB
    no label, UUID=74f8f3e1-6af3-4e51-9ab5-c48e52bf4a7b
  5. Enable the newly created swap space.

    1. Creating and initializing swap space does not yet enable it for use, as shown by the free and swapon -s command.

      [root@server1 ~]# free
                   total       used       free     shared    buffers     cached
      Mem:      1885252     557852    1327400      17096       1080     246040
      -/+ buffers/cache:    310732    1574520
      Swap:           0          0          0
      [root@server1 ~]# swapon -s
      [root@server1 ~]#
    2. Enable the newly created swap space.

      [root@server1 ~]# swapon /dev/vdb2
    3. Verify that the newly created swap space is now available.

      [root@server1 ~]# swapon -s
      Filename                Type        Size    Used    Priority
      /dev/vdb2                               partition   511996  0   -1
    4. Disable the swap space.

      [root@server1 ~]# swapoff /dev/vdb2
    5. Verify that the swap space is disabled.

      [root@server1 ~]# swapon -s
      [root@server1 ~]#
  6. Configure the new swap space so that it is enabled upon boot.

    1. Determine the UUID of the new swap partition on the second disk.

      [root@server1 ~]# blkid /dev/vdb2
      /dev/vdb2:UUID="74f8f3e1-6af3-4e51-9ab5-c48e52bf4a7b" TYPE="swap"
    2. Add an entry to /etc/fstab.

      UUID=74f8f3e1-6af3-4e51-9ab5-c48e52bf4a7b swap swap defaults 0 0
    3. Test enabling the swap space using the entry just added to /etc/fstab.

      [root@server1 ~]# swapon -a
    4. Verify that the new swap space was enabled.

      [root@server1 ~]# swapon -s
      Filename                      Type            Size    Used    Priority
      /dev/vdb2                     partition       511996  0       -1
  7. Reboot server1.example.com. After the server has rebooted, log in and verify that swap space is enabled.

    [student@server1 ~]# swapon -s
    Filename                      Type            Size    Used    Priority
    /dev/vdb2                     partition       511996  0       -1

Your server1.example.com host now has 500 MiB of swap space running on its second disk.